﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GtsServer.DAL;
using GtsServer.Model;
using Pub.Class;
using GtsServer.Common;

namespace GtsServer.Charge.CallBack
{
    /// <summary>
    /// ZhiFuBaoCallback 的摘要说明
    /// </summary>
    public class ZhiFuBaoCallback : IHttpHandler
    {
        string json = string.Empty;
        public void ProcessRequest(HttpContext context)
        {
            LogHelper.WriteLog("dasdas");
            OrderDAL orderDAL = new OrderDAL();
            GtsServer.DAL.PrizeTaskReocrd prizetaskreocrdDAL = new DAL.PrizeTaskReocrd();
            string json = string.Empty;
            json = Request2.GetRequestInputStream().UrlDecode();
            LogHelper.WriteLog(json);
            string orderID = GetTypeName("out_trade_no").ToStr();

            int status = GetTypeName("trade_status") == "TRADE_FINISHED" ? Convert.ToInt32(OrderStutas.成功) : Convert.ToInt32(OrderStutas.不成功);

            if (!string.IsNullOrEmpty(orderID))
                orderDAL.UpdateOrderStutas(orderID, status);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }


        public string GetTypeName(string type)
        {
            return (json.GetMatchingValues("<" + type + ">(.+?)</" + type + ">", "<" + type + ">", "</" + type + ">").FirstOrDefault() ?? "").Trim();
        }
    }
}